import java.util.Stack;

class Solution {
  public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i < tokens.length;i++) {
            String str = tokens[i];
            if(!isOperations(str)) {
                //不是运算符  说明是数字
                int val = Integer.valueOf(str);
                stack.push(val);
            }else {
                //是运算符
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(str) {
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }

        return stack.pop();
    }
    /*判断当前字符串是不是一个运算符 */
    private boolean isOperations(String str) {
        if(str.equals("+") || str.equals("-") || str.equals("*") ||
                str.equals("/")) {
            return true;
        }
        return false;
    }
}